package com.fc.primary.oop;

/**
 * @program: fc-java->DuoTai
 * @description: 多态
 * @author: G_Y
 * @create: 2019-09-05 11:34
 **/
public class DuoTai {
    public static void main(String[] args) {
        Printer printer = new BlackAndWhitePrinter();
        printer.print(new A5("硬A5纸"));
        printer = new ColorPrinter();
        printer.print(new A4("软A4纸"));
    }
}
interface Printer {
    //打印机能在纸上打印
    public void print(Paper paper);
    //打印机报备纸张信息
    public void showPaperIntroduce(String paperDesc);
}
interface Paper {
    //纸张提供自己的类型
    public String getType();
    //纸张提供自己的规格说明
    public String viewIntroduce();
}
abstract class AbstractPaper implements Paper {
    protected String type;
    private AbstractPaper() {
    }
    protected AbstractPaper(String type) {
        this.type = type;
    }
    @Override
    public String getType() {
        return this.type;
    }
}
class A4 extends AbstractPaper {
    public A4(String type) {
        super(type);
    }
    @Override
    public String viewIntroduce() {
        return this.type + ":210×297";
    }
}
class A5 extends AbstractPaper {
    public A5(String type) {
        super(type);
    }
    @Override
    public String viewIntroduce() {
        return this.type + ":148×210";
    }
}
abstract class AbstractPrinter implements Printer{
    @Override
    public void showPaperIntroduce(String paperDesc) {
        System.out.println("打印机自动报备当前使用纸张:");
        System.out.println(paperDesc);
    }
}
class BlackAndWhitePrinter extends AbstractPrinter {
    @Override
    public void print(Paper paper) {
        this.showPaperIntroduce(paper.viewIntroduce());
        System.out.println("这是" + paper.getType() + "黑白打印---");
    }
}
class ColorPrinter extends AbstractPrinter {
    @Override
    public void print(Paper paper) {
        this.showPaperIntroduce(paper.viewIntroduce());
        System.out.println("这是" + paper.getType() + "彩色打印---");
    }
}
